package com.hpu.interceptor;

import android.content.Context;
import android.util.Log;

import com.hpu.tools.ShareTools;

import java.io.IOException;
import java.util.List;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by Liu ZhuangFei on 2018/2/24.
 */

public class ReceivedCookieInterceptor implements Interceptor {

    private Context context;

    public ReceivedCookieInterceptor(Context context) {
        super();
        this.context = context;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
//        //这里获取请求返回的cookie
//        if (!originalResponse.headers("Set-Cookie").isEmpty()) {
//            final StringBuffer cookieBuffer = new StringBuffer();
//            List<String> cookieList=originalResponse.headers("Set-Cookie");
//            String cookieString="";
//            for(String cookie:cookieList){
//                String[] cookieArray = cookie.split(";");
//                cookieString+=cookieArray[0]+";";
//            }
//            Log.i("Cookie",cookieString);
//            ShareTools.put(context,"cookie",cookieString);
//        }

        return originalResponse;
    }
}
